﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ZombieGame
{
    public class Projectile : Entity
    {
        public Player Shooter;
        public Weapon Weapon;
        public List<Zombie> Victims;

        public override float Layer
        {
            get { return 0.91f; }
        }

        public Projectile(Player shooter, float rotation)
            : base()
        {
            Shooter = shooter;
            Weapon = Shooter.Weapon;
            Victims = new List<Zombie>();
            Rotation = rotation;
            Position = shooter.Position;
            Health = 1f;
            Origin = new Vector2(4f, 0.5f);
            Size = new Vector2(8f, 1f);
            Color = Color.White;
            Animation.Add(ZombieGame.Current.Content.Load<Texture2D>("Bullet"));
            ImageData.Add(Drawable.TextureToColor(Animation[0]));
            //51200
            Velocity.X = (float)Math.Cos(Rotation) * 2048f;
            Velocity.Y = (float)Math.Sin(Rotation) * 2048f;
        }

        public override void Dispose()
        {
            Victims = null;
            Weapon = null;
            Shooter = null;
            base.Dispose();
        }

        public override object Clone()
        {
            Projectile clone = new Projectile(Shooter, Rotation);
            clone.Victims = this.Victims;
            clone.Position = this.Position;
            clone.Animation = this.Animation;
            clone.Color = this.Color;
            clone.ImageData = this.ImageData;
            clone.Velocity = this.Velocity;
            clone.Visible = this.Visible;
            clone.State = this.State;
            clone.Frame = this.Frame;
            clone.Position = this.Position;
            clone.Size = this.Size;
            clone.Scale = this.Scale;
            clone.Rotation = this.Rotation;
            clone.Origin = this.Origin;
            clone.Matrix = this.Matrix;
            return clone;
        }

        public override void Update(GameTime time)
        {
            foreach (Wall w in ZombieGame.Current.World.Walls)
                if (w.Collide(this) != new Vector2(-1f))
                    Kill();
            base.Update(time);
        }
    }
}
